
package com.memorytech.starchive.chart;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.View;

public class PieChartView extends View
{
    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private float[] value_degree;

    /**
     * @return the value_degree
     */
    public float[] getValue_degree() {
        return value_degree;
    }

    /**
     * @param value_degree the value_degree to set
     */
    public void setValue_degree(float[] value_degree) {
        this.value_degree = value_degree;
    }

    /**
     * @return the colors_pies
     */
    public int[] getColors_pies() {
        return colors_pies;
    }

    /**
     * @param colors_pies the colors_pies to set
     */
    public void setColors_pies(int[] colors_pies) {
        this.colors_pies = colors_pies;
    }

    private int[] colors_pies;
    RectF rectf = new RectF(170, 45, 470, 345);
    int temp = 90;

    public PieChartView(Context context, float[] values, int[] colors) {

        super(context);
        value_degree = new float[values.length];
        for (int i = 0; i < values.length; i++)
        {
            value_degree[i] = values[i];
        }
        colors_pies = new int[colors.length];
        for (int i = 0; i < colors.length; i++)
        {
            colors_pies[i] = colors[i];
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        for (int i = 0; i < value_degree.length; i++) {
            paint.setColor(colors_pies[i]);
            canvas.drawArc(rectf, temp, value_degree[i], true, paint);
            temp += (int) value_degree[i];
        }
    }
}
